<!--
 * @Author: Nxf
 * @Date: 2022-11-17 21:24:34
 * @LastEditors: Nxf
 * @LastEditTime: 2022-11-18 11:09:30
 * @Descripttion: 
-->
<template>
  <div>
    <a-form-model
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
      ref="productInfoForm"
      class="formStyle"
    >
      <a-row :gutter="10">
        <a-col :span="8">
          <a-form-model-item label="商品编码" class="formItem">
            {{ productInfo.code }}
          </a-form-model-item>
          <a-form-model-item label="商品名称" class="formItem">
            {{ productInfo.name }}
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="规格" class="formItem">
            {{ productInfo.spec }}
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="单位" class="formItem">
            {{ productInfo.uom }}
          </a-form-model-item>
        </a-col>

        <!-- <a-col :span="8">
          <a-form-model-item label="商品ID" class="formItem">
            {{ productInfo.id }}
          </a-form-model-item>
        </a-col> -->

        <a-col :span="8">
          <a-form-model-item label="税务商品名称" class="formItem">
            <span v-if="productInfo.vat_product_id">
              {{ productInfo.vat_product_id[1] }}
            </span>
            <span v-else>
              <span> </span> 订单中提供的税务商品编码不存在, 请维护税务商品:

              <span> {{ productInfo.vat_product_code }} </span>
              <span> {{ productInfo.vat_product_name }} </span>
            </span>
          </a-form-model-item>
        </a-col>
      </a-row>

      <a-form-model-item :wrapper-col="{ span: 14, offset: 20 }">
        <a-button type="primary" @click="onUpdate"> 确认为开票商品 </a-button>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>

<script>
import api from '@/odoorpc'

export default {
  name: 'ProductForm',
  components: {},
  mixins: [],

  data() {
    return {
      records: [],
      labelCol: { span: 6 },
      wrapperCol: { span: 18 }
    }
  },
  props: ['productInfo', 'ncInfo'],
  computed: {},

  watch: {},

  async created() {},

  async mounted() {
    console.log(
      '----------- 111 productInfoForm mounted ---------',
      this.productInfo
    )
  },
  updated() {
    console.log(
      '----------- 111 productInfoForm updated ---------',
      this.productInfo
    )
  },
  methods: {
    async onUpdate() {
      console.log(' update,,,form:::', this.form)

      if (!this.productInfo.vat_product_id) {
        alert('税务编码不存在, 请检查订单数据')
      } else {
        await api.env
          .model('fp.nc.ods.product')
          .write(this.ncInfo.id, { state: 'done' })

        this.$emit('closeModal', false)
      }
    }
  }
}
</script>

<style type="text/css" scoped>
.formStyle {
  padding-left: 20px;
  padding-right: 20px;
}
.formItem {
  /* background-color: red; */
  margin-bottom: 0px;
}
</style>
